namespace CuaHangBanGiay.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class thaydoiclass : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.DonHangs", "nguoidung_id", "dbo.NhanViens");
            DropForeignKey("dbo.DonHangs", "khachhang_id", "dbo.KhachHangs");
            DropForeignKey("dbo.NhapHangs", "nhacc_id", "dbo.NhaCCs");
            DropForeignKey("dbo.NhapHangs", "nhanvien_id", "dbo.NhanViens");
            DropForeignKey("dbo.NhanViens", "nhomnhanvien_id", "dbo.NhomNhanViens");
            DropForeignKey("dbo.PhanHois", "nhanvien_id", "dbo.NhanViens");
            DropForeignKey("dbo.PhanHois", "khachhang_id", "dbo.KhachHangs");
            DropForeignKey("dbo.PhanHois", "topic_id", "dbo.Topics");
            DropForeignKey("dbo.Topics", "nguoitao_id", "dbo.KhachHangs");
            DropForeignKey("dbo.PhanQuyenNhomNhanViens", "PhanQuyen_id", "dbo.PhanQuyens");
            DropForeignKey("dbo.PhanQuyenNhomNhanViens", "NhomNhanVien_id", "dbo.NhomNhanViens");
            DropIndex("dbo.DonHangs", new[] { "nguoidung_id" });
            DropIndex("dbo.DonHangs", new[] { "khachhang_id" });
            DropIndex("dbo.NhapHangs", new[] { "nhacc_id" });
            DropIndex("dbo.NhapHangs", new[] { "nhanvien_id" });
            DropIndex("dbo.NhanViens", new[] { "nhomnhanvien_id" });
            DropIndex("dbo.PhanHois", new[] { "nhanvien_id" });
            DropIndex("dbo.PhanHois", new[] { "khachhang_id" });
            DropIndex("dbo.PhanHois", new[] { "topic_id" });
            DropIndex("dbo.Topics", new[] { "nguoitao_id" });
            DropIndex("dbo.PhanQuyenNhomNhanViens", new[] { "PhanQuyen_id" });
            DropIndex("dbo.PhanQuyenNhomNhanViens", new[] { "NhomNhanVien_id" });
            DropColumn("dbo.DonHangs", "nguoidung_id");
            DropColumn("dbo.DonHangs", "khachhang_id");
            DropColumn("dbo.NhapHangs", "nhacc_id");
            DropColumn("dbo.NhapHangs", "nhanvien_id");
            DropTable("dbo.NhaCCs");
            DropTable("dbo.NhanViens");
            DropTable("dbo.NhomNhanViens");
            DropTable("dbo.PhanQuyens");
            DropTable("dbo.PhanHois");
            DropTable("dbo.KhachHangs");
            DropTable("dbo.Topics");
            DropTable("dbo.ChiPhiVCs");
            DropTable("dbo.PhanQuyenNhomNhanViens");
        }
        
        public override void Down()
        {
            CreateTable(
                "dbo.PhanQuyenNhomNhanViens",
                c => new
                    {
                        PhanQuyen_id = c.Int(nullable: false),
                        NhomNhanVien_id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.PhanQuyen_id, t.NhomNhanVien_id });
            
            CreateTable(
                "dbo.ChiPhiVCs",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        tentinh = c.String(),
                        chiphivc = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.Topics",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        ten = c.String(),
                        noidung = c.String(),
                        ngay = c.DateTime(nullable: false),
                        active = c.Boolean(nullable: false),
                        nguoitao_id = c.Int(),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.KhachHangs",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        tendangnhap = c.String(),
                        tendaydu = c.String(),
                        matkhau = c.String(),
                        diachi = c.String(),
                        email = c.String(),
                        sdt = c.String(),
                        active = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.PhanHois",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        ten = c.String(),
                        noidung = c.String(),
                        ngay = c.DateTime(nullable: false),
                        active = c.Boolean(nullable: false),
                        nhanvien_id = c.Int(),
                        khachhang_id = c.Int(),
                        topic_id = c.Int(),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.PhanQuyens",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        tenquyen = c.String(),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.NhomNhanViens",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        tennhom = c.String(),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.NhanViens",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        tendangnhap = c.String(),
                        tendaydu = c.String(),
                        email = c.String(),
                        matkhau = c.String(),
                        active = c.Boolean(nullable: false),
                        nhomnhanvien_id = c.Int(),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.NhaCCs",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        ten_ncc = c.String(),
                        diachi_ncc = c.String(),
                        sdt_ncc = c.String(),
                        active = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.id);
            
            AddColumn("dbo.NhapHangs", "nhanvien_id", c => c.Int());
            AddColumn("dbo.NhapHangs", "nhacc_id", c => c.Int());
            AddColumn("dbo.DonHangs", "khachhang_id", c => c.Int());
            AddColumn("dbo.DonHangs", "nguoidung_id", c => c.Int());
            CreateIndex("dbo.PhanQuyenNhomNhanViens", "NhomNhanVien_id");
            CreateIndex("dbo.PhanQuyenNhomNhanViens", "PhanQuyen_id");
            CreateIndex("dbo.Topics", "nguoitao_id");
            CreateIndex("dbo.PhanHois", "topic_id");
            CreateIndex("dbo.PhanHois", "khachhang_id");
            CreateIndex("dbo.PhanHois", "nhanvien_id");
            CreateIndex("dbo.NhanViens", "nhomnhanvien_id");
            CreateIndex("dbo.NhapHangs", "nhanvien_id");
            CreateIndex("dbo.NhapHangs", "nhacc_id");
            CreateIndex("dbo.DonHangs", "khachhang_id");
            CreateIndex("dbo.DonHangs", "nguoidung_id");
            AddForeignKey("dbo.PhanQuyenNhomNhanViens", "NhomNhanVien_id", "dbo.NhomNhanViens", "id", cascadeDelete: true);
            AddForeignKey("dbo.PhanQuyenNhomNhanViens", "PhanQuyen_id", "dbo.PhanQuyens", "id", cascadeDelete: true);
            AddForeignKey("dbo.Topics", "nguoitao_id", "dbo.KhachHangs", "id");
            AddForeignKey("dbo.PhanHois", "topic_id", "dbo.Topics", "id");
            AddForeignKey("dbo.PhanHois", "khachhang_id", "dbo.KhachHangs", "id");
            AddForeignKey("dbo.PhanHois", "nhanvien_id", "dbo.NhanViens", "id");
            AddForeignKey("dbo.NhanViens", "nhomnhanvien_id", "dbo.NhomNhanViens", "id");
            AddForeignKey("dbo.NhapHangs", "nhanvien_id", "dbo.NhanViens", "id");
            AddForeignKey("dbo.NhapHangs", "nhacc_id", "dbo.NhaCCs", "id");
            AddForeignKey("dbo.DonHangs", "khachhang_id", "dbo.KhachHangs", "id");
            AddForeignKey("dbo.DonHangs", "nguoidung_id", "dbo.NhanViens", "id");
        }
    }
}
